<template>
  <div class="main" v-loading='loading'>
    <div class="comp_info">
      <div class="trans">
        <div class="comp_auth">
          <img :src='logo' alt />
          <div class="comp_name">
            <div>
              <el-button @click="push('/companySet')" type='text'>编辑</el-button>
              <!-- <router-link to="/companySet">编辑</router-link> -->
            </div>
            <h1>{{form.name}}</h1>
            <p>上次登录：{{form.lastLoginTime}}</p>
          </div>
        </div>
        <div class="authStatus">
          <div>
            <p>企业{{form.authStatus | getName}}</p>
            <span v-if="form.authStatus===2" style="color:rgba(0,155,62,1);">认证通过</span>
            <router-link :to="{path:'/enterprise',query:{companyId:id}}" v-else>{{form.authStatus | getAuth}}
            </router-link>
          </div>
          <div>
            <p>个人{{form.staffAuthStatus | getName}}</p>
            <span v-if="form.staffAuthStatus===2" style="color:rgba(0,155,62,1);">认证通过</span>
            <router-link :to="{path:'/personal',query:{companyId:id}}" v-else>{{form.staffAuthStatus | getAuth}}
            </router-link>
          </div>
          <div>
            <p>社保{{form.socialSecurityAuthStatus | getName}}</p>
            <span v-if="form.socialSecurityAuthStatus===2" style="color:rgba(0,155,62,1);">认证通过</span>
            <router-link :to="{path:'/security',query:{companyId:id}}" v-else>
              {{form.socialSecurityAuthStatus | getAuth}}</router-link>
          </div>
        </div>
      </div>
      <div class="resumeCount">
        <div class="job_manage">
          <div>
            <h1>岗位管理</h1>
            <h2>{{status_1>99?'99+':status_1}}</h2>
            <p>发布中的职位</p>
            <h2>{{status_0>99?'99+':status_0}}</h2>
            <p>审核中的职位</p>
          </div>
          <el-button @click="push('/Release')">发布职位</el-button>
        </div>
        <div class="border"></div>
        <div class="resume_manage">
          <div>
            <h1>简历管理</h1>
            <h2>{{count.noViewCount>99?'99+':count.noViewCount}}</h2>
            <p>未查看的简历</p>
            <h2>{{count.downloadCount>99?'99+':count.downloadCount}}</h2>
            <p>已下载的简历</p>
          </div>
          <el-button @click="push('/resume')">管理简历</el-button>
        </div>
        <div class="border"></div>
        <div class="resume_ser">
          <div>
            <h1>简历搜索</h1>
            <h2>{{count.viewCount>99?'99+':count.viewCount}}</h2>
            <p>浏览过的简历</p>
          </div>
          <el-button @click="push('/TalentPool')">搜索简历</el-button>
        </div>
      </div>
    </div>
    <div class="more">
      <div class="resume">推荐简历</div>
      <el-button @click="push('/TalentPool')">查看更多</el-button>
    </div>
    <div class="resumeList">
      <div class="title"></div>
      <el-table :data="tableData" style="width: 100%" :show-header="false" :row-style="{height:'70px'}"
        :cell-style="{fontSize:'16px'}">
        <el-table-column width="120">
          <template slot-scope="scope">
            <span class="auth_span pointer"
              @click="()=>{toResume(scope.row.id,scope.row.userId)}">{{scope.row.name}}</span>
          </template>
        </el-table-column>
        <el-table-column width="80">
          <template slot-scope="scope">
            <span class="auth_span">{{scope.row.age.slice(0,2)}}岁</span>
          </template>
        </el-table-column>
        <el-table-column prop="educationText" width="100"></el-table-column>
        <el-table-column width="100" align="center">
          <template slot-scope="scope">
            <span
              class="auth_span">{{scope.row.workExpText?scope.row.workExpText:scope.row.workTime&&scope.row.workTime!=='0年'?scope.row.workTime:'无工作经验'}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="hopeJob" align="center"></el-table-column>
        <el-table-column width="300">
          <template slot-scope="scope">
            <span class="auth_span">简历更新时间：{{scope.row.refreshTime}}</span>
          </template>
        </el-table-column>
      </el-table>
      <div class="noData" v-show="tableData.length<=0">
        暂无数据
      </div>
      <el-pagination background layout="prev, pager, next" @current-change="handleCurrentChange" :current-page="page"
        :total="total"></el-pagination>
    </div>
  </div>
</template>

<script>
import { selectCompanyByUserId } from '../../../api/register';
import bus from '../../common/bus'
import { selectResumePage, jobManage, noViewCount, viewCount, downloadCount, validCompany } from '../../../api/home';
export default {
  name: '',
  data () {
    return {
      loading: true,
      logo: '',
      status_1: 0,
      status_0: 0,
      total: 0,
      count: {
        noViewCount: 0,
        viewCount: 0,
        downloadCount: 0
      },
      tableData: [],
      form: {
        name: '',
        socialSecurityAuthStatus: '',
        staffAuthStatus: '',
        authStatus: '',
        lastLoginTime: ''
      },
      id: '',
      page: 1,
      size: 10
    };
  },
  created () {
    // 获取企业信息
    selectCompanyByUserId().then(data => {
      if (data.success) {
        Object.keys(this.form).forEach(item => {
          this.form[item] = data.data[item];
        });
        this.id = data.data.id;
        if (data.data.trade) {
          this.logo = require(`../../../assets/img/logo/${JSON.parse(data.data.trade)[0]}.png`);
        }
        bus.$emit('companyAuth', this.form.authStatus === 2 && this.form.staffAuthStatus === 2);
        this.loading = false;
      } else {
        // this.$message.error(`${data.msg}`);
      }
    });
    this.getList();
    // 获取统计数量
    let file1 = new FormData();
    file1.append('condition', JSON.stringify([{ column: 'status', type: 'eq', value: 1 }]));
    jobManage(file1).then(data => {
      console.log(data);
      this.status_1 = data.data || 0;
    });
    let file0 = new FormData();
    file0.append('condition', JSON.stringify([{ column: 'status', type: 'eq', value: 0 }]));
    jobManage(file0).then(data => {
      this.status_0 = data.data || 0;
    });
    noViewCount().then(data => {
      this.count.noViewCount = data.data || 0;
    });
    viewCount().then(data => {
      console.log(data);
      this.count.viewCount = data.data || 0;
    });
    downloadCount().then(data => {
      console.log(data);
      this.count.downloadCount = data.data || 0;
      console.log(this.count.downloadCount);
    });
  },
  filters: {
    // 获取认证状态
    getName (val) {
      switch (val) {
        case 1:
          return '待认证';
        case 2:
          return '认证通过';
        case 3:
          return '认证未通过';
        default:
          return '未认证';
      }
    },
    getAuth (val) {
      switch (val) {
        case 1:
          return '认证中';
        case 3:
          return '认证失败';
        default:
          return '去认证';
      }
    }
  },
  methods: {
    // 跳转验证
    push (path) {
      if (this.form.authStatus === 2 && this.form.staffAuthStatus === 2) {
        if (path == '/Release') {
          const loading = this.$loading({
            lock: true,
            text: 'Loading',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.7)'
          });
          validCompany().then(res => {
            if (res.success) {
              loading.close()
              this.$router.push({
                path: path
              });
            } else {
              loading.close()
              this.$alert(res.msg, '系统提醒', {
                confirmButtonText: '完善信息',
                callback: action => {
                  this.$router.push({
                    path: '/companySet'
                  })
                }
              });
            }
          })
        } else {
          this.$router.push({
            path: path
          });
        }
      } else {
        this.$message.error('请先进行企业认证和个人认证');
      }
    },
    // 获取简历列表
    getList () {
      selectResumePage({ page: this.page, size: this.size }).then(data => {
        if (data.success) {
          this.total = data.data.total;
          this.tableData = data.data.records;
        } else {
          // this.$message.error(`${data.msg}`);
        }
      });
    },
    // 下一页
    handleCurrentChange (val) {
      this.page = val;
      this.getList();
    },
    toResume (id, userId) {
      if (this.form.authStatus === 2 && this.form.staffAuthStatus === 2) {
        const { href } = this.$router.resolve({
          path: "/resumeManage",
          query: { id, userId, path: 'talent' }
        });
        window.open(href, '_blank');
      } else {
        this.$message.error('请先进行企业认证和个人认证');
      }
    }
  }
};
</script>

<style scoped>
.comp_info {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.trans {
    width: 420px;
    height: 240px;
    background: rgba(255, 255, 255, 1);
    opacity: 1;
    padding: 21px 32px;
    box-sizing: border-box;
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    -ms-box-sizing: border-box;
    -o-box-sizing: border-box;
}
.comp_auth {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.comp_auth img {
    width: 102px;
    height: 102px;
    opacity: 1;
    border-radius: 6px;
    background: url('../../../assets/img/logo/null.png') no-repeat;
    background-size: 100% 100%;
}

.comp_auth .comp_name {
    width: 222px;
    height: 102px;
}
.comp_auth .comp_name div {
    text-align: right;
    height: 20px;
    line-height: 20px;
}
.comp_auth .comp_name div a {
    font-size: 14px;
    font-family: PingFang SC;
    font-weight: 400;
    color: rgba(0, 147, 255, 1);
    opacity: 1;
}
.comp_auth .comp_name h1 {
    overflow: hidden;
    white-space: nowrap;
    height: 28px;
    font-size: 20px;
    font-family: PingFang SC;
    font-weight: 600;
    line-height: 28px;
    color: rgba(51, 51, 51, 1);
    opacity: 1;
    margin-bottom: 16px;
}
.comp_auth .comp_name p {
    height: 20px;
    font-size: 14px;
    font-family: PingFang SC;
    font-weight: 400;
    line-height: 20px;
    color: rgba(85, 85, 85, 1);
    opacity: 1;
}
.authStatus {
    display: flex;
    align-items: center;
    justify-content: space-between;
    text-align: center;
    margin-top: 10px;
}
.authStatus p {
    margin: 10px 0;
    height: 20px;
    font-size: 14px;
    font-family: PingFang SC;
    font-weight: 500;
    line-height: 20px;
    color: rgba(34, 34, 34, 1);
    opacity: 1;
}
.authStatus a {
    display: inline-block;
    height: 20px;
    font-size: 14px;
    font-family: PingFang SC;
    font-weight: 400;
    line-height: 20px;
    color: rgba(0, 147, 255, 1);
    text-decoration: underline;
    opacity: 1;
}
.resumeCount {
    width: 764px;
    height: 240px;
    background: rgba(255, 255, 255, 1);
    opacity: 1;
    padding: 37px 53px;
    box-sizing: border-box;
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    -ms-box-sizing: border-box;
    -o-box-sizing: border-box;
    display: flex;
    flex-direction: row;
    align-items: center;
}
.resumeCount .border {
    width: 0px;
    height: 192px;
    border: 1px solid rgba(232, 232, 232, 1);
    opacity: 1;
    margin: 0 24px;
}
.resumeCount .resume_manage,
.resumeCount .resume_ser,
.resumeCount .job_manage {
    display: flex;
    /* flex-direction: row; */
    align-items: flex-start;
    height: 100%;
}
.resumeCount h1 {
    height: 20px;
    font-size: 14px;
    font-family: PingFang SC;
    font-weight: 500;
    line-height: 20px;
    color: rgba(34, 34, 34, 1);
    opacity: 1;
}
.resumeCount h2 {
    height: 37px;
    font-size: 26px;
    font-family: PingFang SC;
    font-weight: 500;
    line-height: 37px;
    color: rgba(0, 211, 195, 1);
    opacity: 1;
    margin-top: 16px;
}
.resumeCount p {
    height: 20px;
    font-size: 14px;
    font-family: PingFang SC;
    font-weight: 400;
    line-height: 20px;
    color: rgba(34, 34, 34, 1);
    opacity: 1;
}
.resumeCount .el-button {
    width: 94px;
    height: 24px;
    background: rgba(24, 147, 252, 1);
    opacity: 1;
    font-size: 12px;
    font-family: PingFang SC;
    font-weight: 400;
    line-height: 0;
    color: rgba(255, 255, 255, 1);
    text-align: center;
    margin-left: 8px;
}
.more {
    width: 1200px;
    height: 50px;
    background: rgba(255, 255, 255, 1);
    padding: 0 45px;
    opacity: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-sizing: border-box;
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    -ms-box-sizing: border-box;
    -o-box-sizing: border-box;
    margin: 31px 0;
}
.more .resume {
    width: 56px;
    height: 50px;
    font-size: 14px;
    font-family: PingFang SC;
    font-weight: 500;
    color: rgba(34, 34, 34, 1);
    opacity: 1;
    border-bottom: 4px solid rgba(48, 58, 64, 1);
    box-sizing: border-box;
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    -ms-box-sizing: border-box;
    -o-box-sizing: border-box;
    font-size: 14px;
    font-family: PingFang SC;
    font-weight: 500;
    line-height: 50px;
    color: rgba(34, 34, 34, 1);
}
.more .el-button {
    width: 94px;
    height: 24px;
    background: rgba(24, 147, 252, 1);
    opacity: 1;
    font-size: 12px;
    font-family: PingFang SC;
    font-weight: 400;
    line-height: 0;
    color: rgba(255, 255, 255, 1);
    text-align: center;
}
.resumeList {
    width: 1200px;
    height: 853px;
    background: rgba(255, 255, 255, 1);
    opacity: 1;
    text-align: center;
    padding: 0 45px;
    box-sizing: border-box;
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    -ms-box-sizing: border-box;
    -o-box-sizing: border-box;
}
.resumeList .el-pagination {
    margin-top: 25px;
}
.resumeList .pointer {
    cursor: pointer;
    color: rgba(24, 147, 252, 1);
}
.title {
    height: 70px;
    border-bottom: 1px solid rgba(232, 232, 232, 1);
}
.resume_manage h2 {
    color: rgba(252, 164, 24, 1);
}
.resume_ser h2 {
    color: rgba(0, 155, 62, 1);
}
.authStatus span {
    display: inline-block;
    height: 20px;
    font-size: 14px;
    font-family: PingFang SC;
    font-weight: 400;
    line-height: 20px;
    color: rgba(0, 147, 255, 1);
    opacity: 1;
}
.noData {
    width: 100%;
    height: 50px;
    line-height: 50px;
    text-align: center;
    border-top: 1px solid #e5e5e5;
    background: #ffffff;
}
</style>